#!/usr/bin/env python
# -*- coding: utf-8 -*- 

#Kiwi Bot
#Copyright (C) 2009 Mathieu "MathX" Xhonneux
#Modified by @nge1nCorsic4 in 2011

#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License along
#with this program; if not, write to the Free Software Foundation, Inc.,
#51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import kiwi.plugin, kiwi.events, kiwi.config, kiwi.update, kiwi.lang
from os import path
import threading, glob

class admin(kiwi.plugin.Plugin):
	def onStart(self):
		self.commandsRegistered = {}
		self.lang = kiwi.lang.Lang(self, 'admin')
		self.registerEvent(kiwi.events.EVT_CLIENT_SAY,self.onSay)
		self.initCommands = {
		'reboot' : '000001',
		'match' : '000002',
		'team' : '000003',
		'rcon' : '000004',
		'ban' : '000005',
		'rights' : '000006',
		'kick' : '000012',
		'mute' : '000013',
		'setlevel' : '000014',
		'admins' : '000015',
		'list' : '000016',
		'big' : '000019',
		'status' : '000020',
		'veto' : '000022',
		'restart' : '000023',
		'reload' : '000024',
		'version' : '000025',
		'update' : '000026',
		'die' : '000029',
		'exec' : '000030',
		'help' : '000031',
		'red' : '000041',
		'blue' : '000044',
		'pass' : '000048',
		'map' : '000801',
		'next' : '000802'
		}
		self.conf = kiwi.config.configuration('@kiwi/conf/admin.cfg')
		self.cfg = self.conf.settings.list_config_urt
		for name, help in self.initCommands.iteritems():
			if hasattr(self.conf.levels,name):
				level = getattr(self.conf.levels,name)
				if level.isdigit():
					level = int(level)
					if level > -1 and level <= 15:
						if hasattr(self, '_'+name):
							self.commandsRegistered[name] = command(name, level, getattr(self,'_'+name), help)
					elif level == -1:
						pass
					else:
						self.main.log.warn(self.lang.lang('','00027')%(name))
				else:
					self.main.log.warn(self.lang.lang('','00027')%(name))
		self.init()
	def init(self, init=None):
		# if not init:
			# threading.Timer(15, self.init, [True]).start()
		# else:
		self.godUsed = self.checkGod()
		self.cvar = self.cleanList()
		self.current_map = None
		self.Match = False
		self.source = None
		self.checkSource()
		self._reload(5)
	def onStop(self):
		pass
	def onSay(self, event):
		if len(event.message) > 0:
			if event.message[0] == '!':
				message = event.message.split()
				if len(message) >= 1:
					if message[0][1:] in self.commandsRegistered:
						event.command = message[0][1:]
						if len(message) > 1:
							event.arguments = message[1:]
						else:
							event.arguments = []
						client = self.clients.getClientById(event.id)
						if client:
							cmd = self.commandsRegistered[event.command]
							if client[0].rights >= cmd.level and cmd.level != -1:
								cmd.attr(event)
							# else:
								# self.output.tell(event.id, self.lang.lang(event,'00033')%(event.command))
					elif message[0][0:3] == '!be':
						pass
					elif message[0][1:] == 'iamgod':
						if self.godUsed:
							self._iamgod(event)
						# else:
							# self.output.tell(event.id,self.lang.lang(event,'00102'))
					# else:
						# self.output.tell(event.id,self.lang.lang('','00102'))
			elif self.Match :
				message = event.message.split()
				if event.id == self.id:
					if len(message) == 1:
						if self.password:
							if message[0] == 'oui':
								self.confirm = True
							elif message[0] == 'non':
								self.password = None
								self.output.tell(self.id,"^7%s"%self.lang.lang(event,"00076"))
						else:
							self.password = message[0]
							self.viewConfirm = True
					else:
						# if message[0][0] != '!':
						self.output.tell(self.id,"^1%s"%self.lang.lang(event,"00077"))
	def registerCommand(self, name, level, functionAttr, help = None):
		self.commandsRegistered[name] = command(name, level, functionAttr, help)
	def deleteCommand(self,name):
		if name in self.commandsRegistered:
			del self.commandsRegistered[name]
			return True
		return False
	def checkGod(self):
		if len(self.clients.rights) == 0:
			if self.conf.settings.god == 'yes':
				return True
		return False
	def getConfigs(self,event):
		cfg = self.cfg.split(",")
		self.output.tell(event.id,"^4%s"%self.lang.lang(event,"00075"))
		count = 1
		for file in cfg :
			self.output.tell(event.id,"^1%s ^7: ^3%s"%(str(count),file))
			count+=1
	def getRight(self, client):
		rightlist = self.clients.rights	
		list = []
		for i in rightlist:
			# if type(rightlist[i]) != int :
			if client == rightlist[i][0]:
				list.append(i)
		return list
	def passwd(self,event):
		if self.Match :
			message = event.message.split()
			if event.id == self.id:
				if len(message) == 1:
					if self.password:
						if message[0] == 'oui':
							self.confirm = True
						elif message[0] == 'non':
							self.password = None
							self.output.tell(self.id,"^7%s"%self.lang.lang(event,"00076"))
					else:
						self.password = message[0]
						self.viewConfirm = True
				else:
					if message[0][0] != '!':
						self.output.tell(self.id,"^1%s"%self.lang.lang(event,"00077"))
	def Parseconfig(self,event,cfg,conf):
		if self.Match:
			if self.password:
				if self.confirm:
					self.Match = False
					self.output.send('mute %s'%event.id)
					self.output.tell(event.id,"^5%s ^1%s"%(self.lang.lang(event,"00078"),self.password))
					self.output.send('g_password %s'%self.password)
					self.output.send('exec %s'%(cfg[conf]))
					self.password = None
				else:
					if self.viewConfirm :
						self.SendConfirm(event)
			if self.Ptimer + 60 < kiwi.getTime():
				self.Match = False
				self.password = None
				self.output.tell(event.id,self.lang.lang(event,"00044"))
			else:
				threading.Timer(1, self.Parseconfig,[event,cfg,conf]).start()
	def ParsePassword(self,event):
		if self.Match:
			if self.password:
				if self.confirm:
					self.Match = False
					self.output.send('mute %s'%event.id)
					self.output.tell(event.id,"^5%s ^1%s"%(self.lang.lang(event,"00078"),self.password))
					self.output.send('g_password %s'%self.password)
					self.reload()
					self.password = None
				else:
					if self.viewConfirm :
						self.SendConfirm(event)
			threading.Timer(1, self.ParsePassword,[event]).start()
	def reload(self, nb=None):
		if nb:
			self.output.bigtext('^4%s ^3%ss'%(self.lang.lang('','00074'),nb))
			if nb > 1 :
				nb -= 1
				threading.Timer(1, self.reload,[nb]).start()
			else:
				self.output.send('reload')
		else:
			threading.Timer(1, self.reload,[20]).start()
	def SendConfirm(self,event):
		self.viewConfirm = False
		if self.password:
			self.output.tell(event.id,self.lang.lang(event,"00079")%self.password)
			threading.Timer(10, self.SendConfirm,[event]).start()
	def cleanList(self):
		list = []
		cvarfile = kiwi.getPath("@kiwi/files/cvar.list")
		if path.isfile(cvarfile):
			f = file(cvarfile,'r')
			cvar = f.readlines()
			f.close()
		else:
			self.main.log.warn(self.lang.lang('','1304'))
			self.deleteCommand('rcon')
			return None
		for a in cvar:
			a = a.strip()
			list.append(a)
		return list
	def checkRcon(self, event):
		argu = event.arguments[0]
		cmd = []
		for command in self.cvar:
			if argu in command:
				cmd.append(command)
		if len(cmd) == 0:
			return '^4%s'%(self.lang.lang(event,'01301'))
		elif len(cmd) == 1:
			return cmd
		else:
			message = ('^4%s ^3'%(self.lang.lang(event,'01302')))
			message += '^1, ^3'.join(cmd)
			return message+'^1.'
	def rcon_message(self, event):
		message = self.checkRcon(event)
		if len(message) == 1:
			if len(event.arguments) > 1:
				self.output.tell(event.id, '^4%s ^3%s ^2[^7%s^2]'%(self.lang.lang(event,'01303'), message[0], event.arguments[1]))
				return message[0]
			else:
				return message[0]
		else:
			self.output.tell(event.id, message)
			return False
	def checkSource(self):
		if not self.source:
			source = []
			p = self.output.send('fs_basepath')
			if 'fs_basepath' in p :
				p = p.split('"')[3]
				p = p.split('^')[0]
				self.s = p+'/q3ut4/'
				if path.isdir(self.s):
					source.append(self.s)
				Game_Source = kiwi.config.configuration().server.log_game
				Game_Source = Game_Source.split('q3ut4')[0]
				source.append(Game_Source+'q3ut4/')
				self.source = source
				self.GetAllmap()
			else:
				threading.Timer(5, self.checkSource).start()
		return self.source
	def GetAllmap(self):
		f = file(kiwi.getPath('@kiwi/files/officiel.txt'),'r')
		t = f.readlines()
		f.close()
		for p in self.source:
			files = '*.pk3'
			Maps = glob.glob(p+files)
			for f in Maps:
				a = f.split("/")
				d = a[-1]
				if not 'zpak' in d[0:4] :
					t.append(d.split('.pk3')[0])
		self.list = []
		for m in t:
			self.list.append(m.strip())
	def getmaps(self, event):
		argu = event.arguments[0]
		if self.list :
			nb = 0
			for txt in self.list:
				if argu in txt:
					nb = nb+1
			if nb == 0:
				return '^4%s'%(self.lang.lang(event,'00807'))
			elif nb == 1:
				for txt in self.list:
					if argu in txt:
						return [txt]
			elif nb > 1 and nb <= 30:
				if len(event.arguments) > 1 :
					for txt in self.list:
						if argu == txt:
						# if argu == txt[:-1]:
							return [txt]
					self.output.tell(event.id,self.lang.lang('','00817'))
					event.arguments.remove(event.arguments[1])
				message = ('^4%s '%(self.lang.lang(event,'00818')))
				for txt in self.list:
					if argu in txt:
						message += ' ^3%s ^1| '%(txt)
				return message[:-2]+'.'
			else:
				return '^4%s'%(self.lang.lang(event,'00808'))
		else:
			self.output.tell(event.id, self.lang.lang(event,'00820'))
	def message(self, event):
		if len(event.arguments) > 0:
			message = self.getmaps(event)
			if len(message) == 1:
				self.output.tell(event.id, '^4%s ^3%s'%(self.lang.lang(event,'00819'), message[0]))
				return message[0]
			else:
				self.output.tell(event.id, message)
				return False
		else:
			self.output.tell(event.id, self.lang.lang(event,'00101'))
			return False
	def _rights(self, event):
		list = self.clients.rights
		text = ''
		for guid in list:
			# print list[guid][0], list[guid][1]
			name = list[guid][0]
			level = list[guid][1]
			if level > 0 :
				if len(event.arguments) > 0 :
					argu = event.arguments[0]
					if argu.isdigit():
						if int(argu) == level:
							text += '^3%s^4[^7%s^4] ^1| '%(name,level)
					elif argu in name.lower() :
						if len(argu) > 3 :
							if len(event.arguments) > 1 :
								client = self.getRight(name)
								Newlevel = int(event.arguments[1])
								if len(client) == 0:
									text = self.lang.lang(event,"00103")
								elif len(client) == 1:
									if Newlevel == 0:
										text = self.lang.lang(event,"00907")%name
									elif Newlevel > 0 and Newlevel <= 15 :
										text = self.lang.lang(event,"00905")%(Newlevel, name)
									else:
										self.output.tell(event.id,self.lang.lang(event,"00906"))
										return
									self.clients.setRights(guid, name, Newlevel)
									break
								elif len(event.arguments) > 2 and Newlevel == 0 :
									for c in client :
										self.clients.setRights(c, name, Newlevel)
									text = self.lang.lang(event,"00907")%name
								else:
									text = self.lang.lang(event,"00104")
							else:
								text += '^3%s^4[^7%s^4] ^1| '%(name,level)
						else:
							self.output.tell(event.id,'Minimum 4 caracteres pour le pseudo !!')
							return
							
				else:
					text += '^3%s^4[^7%s^4] ^1| '%(name,level)
		if len(text) == 0 :
			text = self.lang.lang(event,"00103")
		print text
		self.output.tell(event.id,text)
	def _iamgod(self, event):
		client = self.clients.getClientById(event.id)[0]
		self.clients.setRights(client.guid,client.name,10)
		self.output.tell(event.id,self.lang.lang(event,'00034'))
		self.godUsed = False
	def _update(self, event):
		self.current = kiwi.update.Update(self)
		self.output.tell(event.id,self.lang.lang(event,'00051'))
		response = self.current.update()
		if response:
			maj = '^4%s %s.'%(self.lang.lang(event,'00052'),response[:-2])
		else:
			maj = self.lang.lang(event,'00053')
		self.output.tell(event.id,maj)
	def _version(self, event):
		path = kiwi.getPath('@version')
		f = file(path,'r')
		version = f.read()
		f.close()
		self.output.tell(event.id,version)
	def _map(self, event):
		if len(event.arguments) > 0:
			message = self.message(event)
			if message :
				self.output.send('map %s'%message)
	def _next(self, event):
		if len(event.arguments) > 0:
			message = self.message(event)
			if message :
				self.output.send('g_nextmap %s'%message)
	def _kick(self, event):
		if len(event.arguments) > 0:
			if event.arguments[0] == 'all' :
				self.output.send('kick all')
			else:
				if len(event.arguments) > 1:
					arguments = ' '.join(event.arguments[1:])
				else:
					arguments = 'None'
				clients = self.clients.getClientByInput(event.arguments[0])
				clientName = self.clients.getClientById(event.id)[0].name
				client = clients[0]
				if len(clients) == 0:
					self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00103'))
				elif len(clients) == 1:
					self.output.send('kick %s'%(client.id))
					self.main.log.kick(self.lang.lang('', '00058')%(clientName, client.name, arguments))
				else:
					self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00104'))
		else:
			self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00101'))
	def _ban(self, event):
		if len(event.arguments) > 0:
			if len(event.arguments) > 1:
				arguments = ' '.join(event.arguments[1:])
			else:
				arguments = 'None'
			clientban = self.clients.getClientByInput(event.arguments[0])
			if len(clientban) == 0:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00103'))
			elif len(clientban) == 1:
				c = clientban[0]
				self.output.send('addip %s'%(c.ip))
				self.output.send('kick %s'%(c.id))
				clientName = self.clients.getClientById(event.id)[0].name
				self.output.tell(event.id,self.lang.lang('', '00056')%(clientName, c.name, arguments))
				self.main.log.ban(self.lang.lang('', '00056')%(clientName, c.name, arguments))
			else:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00104'))
		else:
			self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00101'))
	def _mute(self, event):
		if len(event.arguments) > 0:
			clients = self.clients.getClientByInput(event.arguments[0])
			if len(clients) == 0:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00103'))
			elif len(clients) == 1:
				self.output.send('mute %s'%(clients[0].id))
			else:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00104'))
		else:
			self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00101'))
	def _blue(self, event):
		if len(event.arguments) > 0:
			clients = self.clients.getClientByInput(event.arguments[0])
			if len(clients) == 0:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00103'))
			elif len(clients) == 1:
				self.output.send('forceteam %s blue'%(clients[0].id))
			else:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00104'))
		else:
			self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00101'))
	def _red(self, event):
		if len(event.arguments) > 0:
			clients = self.clients.getClientByInput(event.arguments[0])
			if len(clients) == 0:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00103'))
			elif len(clients) == 1:
				self.output.send('forceteam %s red'%(clients[0].id))
			else:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00104'))
		else:
			self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00101'))
	def _big(self, event):
		if len(event.arguments) > 0:
			text = ' '.join(event.arguments)
			clientName = self.clients.getClientById(event.id)[0].name
			self.output.bigtext(text)
		else:
			self.output.tell(event.id, self.lang.lang(event,'00101'))
	def _help(self, event):
		if len(event.arguments) == 0:
			message = ('^4%s '%self.lang.lang(event, '00061'))
			for cmd in self.commandsRegistered.itervalues():
				if cmd.level <= self.clients.getClientById(event.id)[0].rights:
					message += ' ^3%s^1|'%(cmd.name)
			message = message[:-3]+'^1.'
			self.output.tell(event.id,message)
		else:
			cmd = event.arguments[0]
			if cmd in self.commandsRegistered:
				cmd = self.commandsRegistered[cmd]
				if cmd.level <= self.clients.getClientById(event.id)[0].rights:
					if cmd.help:
						if cmd.help.isdigit():
							help = self.lang.lang(event, cmd.help)
						else:
							help = cmd.help
						message = '^4%s ^1%s : ^3%s'%(self.lang.lang(event, '00062'), cmd.name, help)
					else:
						message = '^4%s ^3%s'%(self.lang.lang(event, '00063'), cmd.name)
				else:
					message = '^4%s ^3%s'%(self.lang.lang(event, '00063'), cmd.name)
			self.output.tell(event.id,message)
	def _setlevel(self, event):
		if len(event.arguments) > 1:
			if event.arguments[1].isdigit():
				level = int(event.arguments[1])
				if level > -1 and level <= 15:
					client = self.clients.getClientByInput(event.arguments[0])
					if len(client) == 0:
						self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00103'))
					elif len(client) == 1:
						client = client[0]
						if self.clients.setRights(client.guid, client.name, level):
							self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00065'))
						else:
							self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00066'))
					else:
						self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00104'))
				else:
					self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00067'))
			else:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00067'))
		else:
			self.output.tell(event.id,self.lang.lang(event,'00101'))
	def _admins(self, event):
		clients = self.clients.getClientsList()
		text = '^4%s'%self.lang.lang(event, '00068')
		for c in clients:
			if c.rights > 0:
				text += '^3%s ^1[%s]^3, '%(c.name,c.rights)
		text = text[:-2]+'.'
		self.output.tell(event.id,text)
	def _list(self, event):
		clients = self.clients.getClientsList()
		text = '^4%s'%self.lang.lang(event, '00069')
		for c in clients:
			text += '^3%s ^1[%s]^3, '%(c.name,c.id)
		text = text[:-2]+'.'
		self.output.tell(event.id,text)
	def _veto(self, event):
		self.output.send('veto')
	def _restart(self, event):
		if len(event.arguments) > 0 :
			if event.arguments[0].isdigit():
				nb = event.arguments[0]
			else:
				self.output.tell(event.id,self.lang.lang('','00106'))
				return
		else :
			nb = 10
		while nb != 0 :
			self.output.bigtext('^4%s ^3%ss'%(self.lang.lang('','00073'),nb))
			nb = int(nb)-1
		self.output.send('restart')
	def _reload(self, event):
		if type(event) == int :
			nb = event
		else:
			if len(event.arguments) > 0 :
				if event.arguments[0].isdigit():
					nb = event.arguments[0]
				else:
					self.output.tell(event.id,self.lang.lang('','00106'))
					return
			else :
				nb = 10
		while nb != 0 :
			self.output.bigtext('^4%s ^3%ss'%(self.lang.lang('','00074'),nb))
			nb = int(nb)-1
		self.output.send('reload')
	def _status(self, event):
		if len(event.arguments) > 0:
			clients = self.clients.getClientByInput(event.arguments[0])
			if len(clients) == 0:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00103'))
			elif len(clients) == 1:
				client = clients[0]
				dns = client.dns
				if dns:
					dns = self.lang.lang(event, '00070')%dns
				else:
					dns = self.lang.lang(event, '00071')
				text = self.lang.lang(event, '00072') %(client.name,client.id,client.rights,client.ip,dns)
				self.output.tell(event.id, text)
			else:
				self.output.tell(event.id,'^4%s'%self.lang.lang(event, '00104'))
		else:
			self.output.tell(event.id,self.lang.lang(event,'00101'))
	def _exec(self, event):
		if len(event.arguments) > 0:
			self.output.send('exec %s'%(event.arguments[0]))
		else:
			self.output.tell(event.id,self.lang.lang(event,'00101'))
	def _match(self, event):
		if len(event.arguments) > 0:
			if not self.Match:
				if event.arguments[0].isdigit() :
					cfg = self.cfg.split(",")
					conf = int(event.arguments[0]) - 1
					if conf < len(cfg):
						self.Ptimer = kiwi.getTime()
						self.Match = True
						self.id = event.id
						self.password = None
						self.confirm = False
						self.output.tell(self.id,self.lang.lang(event,"00080")%cfg[conf])
						self.output.tell(self.id,"^7%s"%self.lang.lang(event,"00081"))
						self.output.send('mute %s'%self.id)
						self.Parseconfig(event,cfg,conf)
					else:
						self.output.tell(event.id,self.lang.lang(event,"00082"))
				else:
					self.output.tell(event.id,'^1%s'%self.lang.lang(event,"00083"))
					self.getConfigs(event)
			else:
				self.output.tell(event.id,"^1%s"%self.lang.lang(event,"00084"))
		else:
			self.getConfigs(event)
	def _pass(self, event):
		if len(event.arguments) < 1:
			if not self.Match:
				self.Match = True
				self.id = event.id
				self.password = None
				self.confirm = False
				self.output.tell(self.id,"^7%s"%self.lang.lang(event,"00081"))
				self.output.send('mute %s'%self.id)
				self.ParsePassword(event)
		else:
			self.output.tell(event.id,self.lang.lang(event,'00043'))
	def _team(self, event):
		if len(event.arguments) > 0 :
			argu = event.arguments[0]
			team1, team2 = 'red', 'blue'
			if len(event.arguments) > 1 :
				teams = event.arguments[1]
				if teams == 'red' :
					team1, team2 = teams, 'blue'
				elif teams == 'blue' :
					team1, team2 = teams, 'red'
				else:
					self.output.tell(event.id, self.lang.lang(event,'00953'))
					return
			clients = self.clients.getClientsList()
			list1, list2 = [], []
			for c in clients :
				if int(c.team) != 3 :
					if argu in c.name.lower() :
						# print argu, c.name
						list1.append(c.id)
					else :
						list2.append(c.id)
			if len(list1) > len(list2) :
				listA, teamA, listB, teamB = list1, team1, list2, team2
			else:
				listB, teamB, listA, teamA = list1, team1,  list2, team2
			while len(listA) > 0 :
				if len(listA) > 0 :
					self.output.send('forceteam %s %s'%(listA[0], teamA))
					listA.remove(listA[0])
				if len(listB) > 0 :
					self.output.send('forceteam %s %s'%(listB[0], teamB))
					listB.remove(listB[0])
				self.output.bigtext(self.lang.lang('','00955')%argu)
	def _rcon(self, event):
		if len(event.arguments) > 0:
			message = self.rcon_message(event)
			if message :
				if len(event.arguments) > 1:
					self.output.send('%s %s'%(message, event.arguments[1]))
				else:
					# self.output.send('%s'%message)
					# time.sleep(0.2)
					reponse = self.output.send('%s'%message)
					self.output.tell(event.id, reponse)
		else:
			self.output.tell(event.id, self.lang.lang(event,'00101'))
	def _die(self, event):
		self.output.tell(event.id, self.lang.lang(event,'00054'))
		self.main.main.onStop()
	def _reboot(self, event):
		fullpath = self.conf.settings.reboot
		self.output.tell(event.id, fullpath)
		if path.isfile(fullpath):
			# self.output.tell(event.id, self.lang.lang(event,'00055'))
			self.main.main.reboot(fullpath)
		else:
			self.output.tell(event.id, self.lang.lang(event,'00021'))
			
class command:
	def __init__(self, name, level, attr, help):
		self.name = name
		self.level = level
		self.attr = attr
		self.help = help
